package cn.minsh.lims.eoms.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Administrator
 */
@Configuration
public class RabbitMQConfig {

    /**交换机名称*/
    @Value("${spring.rabbitmq.item_topic_exchange}")
    public  String itemTopicExchange ;
    /**队列名称*/
    @Value("${spring.rabbitmq.item_queue}")
    public String itemQueue;

    /**
     * 声明交换机
     */
    @Bean("itemTopicExchange")
    public Exchange topicExchange(){
        return ExchangeBuilder.topicExchange(itemTopicExchange).durable(true).build();
    }

    /**
     * 声明队列
     * @return
     */
    @Bean("itemQueue")
    public Queue itemQueue(){
        return QueueBuilder.durable(itemQueue).build();
    }

    /**
     * 绑定队列和交换机
     */
    @Bean
    public Binding itemQueueExchange(@Qualifier("itemQueue") Queue queue,
                                     @Qualifier("itemTopicExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("item.#").noargs();
    }
}
